//
//  NSMutableAttributedString+category.m
//  ESport
//
//  Created by mac  on 14-11-27.
//  Copyright (c) 2014年 kdong. All rights reserved.
//

#import "NSMutableAttributedString+category.h"



@implementation NSMutableAttributedString (category)

+ (NSMutableAttributedString *)attributeStrWithText:(NSString *)text color1:(UIColor *)color1 color2:(UIColor *)color2 font1:(UIFont *)font1 font2:(UIFont *)font2
{
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
    NSRange range = [text rangeOfString:@"："];
    
    [attr setAttributes:@{NSForegroundColorAttributeName:color1,
                          NSFontAttributeName:font1
                          } range:NSMakeRange(0, range.location + 1)];
    [attr setAttributes:@{NSForegroundColorAttributeName:color2,
                          NSFontAttributeName:font2
                          } range:NSMakeRange(range.location + 1, text.length - range.location -1)];
    return attr;
}

+ (NSMutableAttributedString *)attributeVenueStrWithText:(NSString *)text color1:(UIColor *)color1 color2:(UIColor *)color2 font1:(UIFont *)font1 font2:(UIFont *)font2
{
    NSString *str = [NSString stringWithFormat:@"%.2f起",text.floatValue];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
    NSRange range = [str rangeOfString:@"起"];
    
    [attr setAttributes:@{NSForegroundColorAttributeName:color1,
                          NSFontAttributeName:font1
                          } range:NSMakeRange(0, range.location + 1)];
    [attr setAttributes:@{NSForegroundColorAttributeName:color2,
                          NSFontAttributeName:font2
                          } range:range];
    return attr;
}

+ (NSMutableAttributedString *)attributeVenueStrWithText:(NSString *)text1 text2:(NSString *)text2 color1:(UIColor *)color1 color2:(UIColor *)color2 font1:(UIFont *)font1 font2:(UIFont *)font2
{
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",text1,text2]];
    
    [attr setAttributes:@{NSForegroundColorAttributeName:color1,
                          NSFontAttributeName:font1} range:NSMakeRange(0, text1.length)];
    [attr setAttributes:@{NSForegroundColorAttributeName:color2,
                          NSFontAttributeName:font2} range:NSMakeRange(text1.length, text2.length)];
    return attr;
}

+ (NSMutableAttributedString *)attributeVenueStrWithText:(NSString *)text1 text2:(NSString *)text2  text3:(NSString *)text3 color1:(UIColor *)color1 color2:(UIColor *)color2 font1:(UIFont *)font1 font2:(UIFont *)font2
{
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@",text1,text2,text3]];
    
    [attr setAttributes:@{NSForegroundColorAttributeName:color1,
                          NSFontAttributeName:font1} range:NSMakeRange(0, text1.length)];
    [attr setAttributes:@{NSForegroundColorAttributeName:color2,
                          NSFontAttributeName:font2} range:NSMakeRange(text1.length, text2.length)];
    [attr setAttributes:@{NSForegroundColorAttributeName:color1,
                          NSFontAttributeName:font2} range:NSMakeRange(text2.length + text1.length, text3.length)];
    return attr;
}



@end
